package meeting0201;


import java.util.HashSet;
import java.util.Set;

import node.ListNode;
import node.ListNodeManager;

/**
 * 示例1:
 * <p>
 * 输入：[1, 2, 3, 3, 2, 1]
 * 输出：[1, 2, 3]
 * 示例2:
 * <p>
 * 输入：[1, 1, 1, 1, 2]
 * 输出：[1, 2]
 */
public class Solution {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 3, 2, 1};
        ListNode head = ListNodeManager.createListNodeByArray(nums);
        ListNodeManager.printlnNode(removeDuplicateNodes(head));
    }

    private static Set<Integer> set = new HashSet<>();
    public static ListNode removeDuplicateNodes(ListNode head) {
        if (head == null)
            return head;
        if (set.contains(head.val)) {
            return removeDuplicateNodes(head.next);
        } else {
            set.add(head.val);
            head.next = removeDuplicateNodes(head.next);
            return head;
        }
    }
}
